<?php
namespace Home\Controller;
use Common\Controller\UserController;
class OrderController extends UserController {
     public function order_list(){
        if (session('id')) {
            $cid=session('id');
            $orderModel=M('order');
            $addModel=M('merchandise_order');
            $result=$orderModel->where('comuser_id='.$cid)->select();
            foreach ($result as $key => $value) {
                $result[$key]['product']=$addModel->where('order_id='.$value['id'])->select();
            }
            $this->assign('order',$result);
        }else{
            header('Location:'.U('Index/login'));
        }       
        $this->display();
    }
    public function obligations(){
        $cid=session('id');
        $orderModel=M('order');
        $addModel=M('merchandise_order');
        $result=$orderModel->where('comuser_id='.$cid. ' and status=1')->select();
        foreach ($result as $key => $value) {
            $result[$key]['product']=$addModel->where('order_id='.$value['id'])->select();
        }
        $this->assign('order',$result);      
        $this->display();
    }
    public function shipment(){
        $cid=session('id');
        $orderModel=M('order');
        $addModel=M('merchandise_order');
        $result=$orderModel->where('comuser_id='.$cid. ' and status=2')->select();
        foreach ($result as $key => $value) {
            $result[$key]['product']=$addModel->where('order_id='.$value['id'])->select();
        }
        $this->assign('order',$result);        
        $this->display();
    }
    public function received(){
        $cid=session('id');
        $orderModel=M('order');
        $addModel=M('merchandise_order');
        $result=$orderModel->where('comuser_id='.$cid. ' and status=3')->select();
        foreach ($result as $key => $value) {
            $result[$key]['product']=$addModel->where('order_id='.$value['id'])->select();
        }
        $this->assign('order',$result); 
        $this->display();
    }
}